package com.dao.Impl;

import com.dao.StorageinfoDao;
import com.entity.PageBean;
import com.entity.Storageinfo;
import com.util.JDBC;
import com.util.TransBean;

import java.util.List;
import java.util.Map;

public class StorageinfoDaoImpl implements StorageinfoDao {
    @Override
    public List<Storageinfo> findBystorageId(int storageId) {
        List<Map> maps = JDBC.selectMap("select id,storageId,goodsId,goodsPrice,goodsCount,momo from storageinfo " +
                " where storageId=?", storageId);
        List<Storageinfo> slist = TransBean.populate(Storageinfo.class, maps);
        if(slist!=null&&slist.size()>0){
            return slist;
        }
        return null;
    }

    @Override
    public int insertStorageinfo(Storageinfo si) {
        return JDBC.sqlUpdate("insert into storageinfo(storageId,goodsId,goodsPrice,goodsCount) values(?,?,?,?)",
                si.getStorageId(),
                si.getGoodsId(),
                si.getGoodsPrice(),
                si.getGoodsCount()
        );
    }

    @Override
    public void pageFindStoraginfo(PageBean page) {
        String sql="select count(*) from storage";
        List<List> lists = JDBC.selectArray(sql);
        page.setRowCount(((Long)lists.get(0).get(0)).intValue());
        page.getTotalPage();
        page.setStartIndex();
        sql=String.format("select s1.storageId,s2.staffName,s1.createTime,s1.price,s1.status,s1.momo from storage s1,staff s2 where s1.staffId=s2.staffId limit ?,?");
        List<Map> listList=JDBC.selectMap(sql,(page.getPageNo() - 1) * page.getPageSize(), page.getPageSize());
        if (listList.size()>0){
            page.setData(listList);
        }
    }

}
